<?php
class Grid_Product_Product extends OeZend_Widget_Grid {
    public function init() {


        $collectionColumn = new OeZend_Widget_Grid_Collection_Column();

        $codeColumn = new OeZend_Widget_Grid_Column('code');
        $linkCode   = '<a href="/admin/product/update/id/${id}">${code}</a>';
        $codeColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($linkCode));
        $codeColumn->setFilter('Text');
        $codeColumn->setLabel('Code');
        $codeColumn->addAttribute(array('style' => 'width:60px;'));

        $nameColumn = new OeZend_Widget_Grid_Column('name');
        $linkName   = '<a href="/admin/product/update/id/${id}">${name}</a>';
        $nameColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($linkName));
        $nameColumn->setFilter('Text');
        $nameColumn->setLabel('Name');

        $categoryColumn = new OeZend_Widget_Grid_Column('product_category_title');
        $categoryColumn->setFilter('Combobox');
        $categoryColumn->setLabel('Category');

        $parentCategoryColumn = new OeZend_Widget_Grid_Column('parent_product_category_title');
        $parentCategoryColumn->setFilter('Combobox');
        $parentCategoryColumn->setLabel('Parent category');


        $priceSaleColumn = new OeZend_Widget_Grid_Column('price_sale');
        $priceSaleColumn->setFilter(new OeZend_Widget_Grid_Filter_Range(null, null, null, ''));
        $priceSaleColumn->setLabel('Price');

        $priceSaleOffColumn = new OeZend_Widget_Grid_Column('price_sale_off');
        $priceSaleOffColumn->setFilter(new OeZend_Widget_Grid_Filter_Range(null, null, null, ''));
        $priceSaleOffColumn->setLabel('Sale Off');

        $productStatusColumn = new OeZend_Widget_Grid_Column('product_status_title');
        $productStatusColumn->setLabel('Status');
        $productStatusColumn->setFilter('Combobox');

        $statusColumn = new OeZend_Widget_Grid_Column('status_label');
        $statusColumn->setFilter('Combobox');
        $statusColumn->setLabel('Public');
        $callBackFunction = function ($rs) {
                                $class = 'ajax-link-must-confirm popup hint  label';
                                return ($rs['status'] == Model_DbTable_Product::STATUS_ACTIVE)
                                ? '<a href="##" class="'. $class .' label-success" data-ajax-to="/admin/product/change-value?p=public&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="No">Yes</a>'
                                : '<a href="##" class="'. $class .' label-warning" data-ajax-to="/admin/product/change-value?p=public&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="Yes">No</a>';
                            };
        $statusColumn->setContent(new OeZend_Widget_Grid_Column_Content_CallBack($callBackFunction));
        $statusColumn->addAttribute(array('class' => 'center'));

        $isNewColumn = new OeZend_Widget_Grid_Column('is_new_label');
        $isNewColumn->setFilter('Combobox');
        $isNewColumn->setLabel('New');
        $callBackFunction = function ($rs) {
                                $class = 'ajax-link-must-confirm popup hint  label';
                                return ($rs['is_new'] == Model_DbTable_Product::STATUS_ACTIVE)
                                ? '<a href="##" class="'. $class .' label-success" data-ajax-to="/admin/product/change-value?p=isNew&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="No">Yes</a>'
                                : '<a href="##" class="'. $class .' label-warning" data-ajax-to="/admin/product/change-value?p=isNew&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="Yes">No</a>';
                            };
        $isNewColumn->setContent(new OeZend_Widget_Grid_Column_Content_CallBack($callBackFunction));
        $isNewColumn->addAttribute(array('class' => 'center'));

        $isSaleOffColumn = new OeZend_Widget_Grid_Column('is_sale_off_label');
        $isSaleOffColumn->setFilter('Combobox');
        $isSaleOffColumn->setLabel('Sale Off');
        $callBackFunction = function ($rs) {
                                $class = 'ajax-link-must-confirm popup hint  label';
                                return ($rs['is_sale_off'] == Model_DbTable_Product::STATUS_ACTIVE)
                                ? '<a href="##" class="'. $class .' label-success" data-ajax-to="/admin/product/change-value?p=isSaleOff&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="No">Yes</a>'
                                : '<a href="##" class="'. $class .' label-warning" data-ajax-to="/admin/product/change-value?p=isSaleOff&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="Yes">No</a>';
                            };
        $isSaleOffColumn->setContent(new OeZend_Widget_Grid_Column_Content_CallBack($callBackFunction));
        $isSaleOffColumn->addAttribute(array('class' => 'center'));

        $isFeaturedColumn = new OeZend_Widget_Grid_Column('is_featured_label');
        $isFeaturedColumn->setFilter('Combobox');
        $isFeaturedColumn->setLabel('Featured');
        $callBackFunction = function ($rs) {
                                $class = 'ajax-link-must-confirm popup hint  label';
                                return ($rs['is_featured'] == Model_DbTable_Product::STATUS_ACTIVE)
                                ? '<a href="##" class="'. $class .' label-success" data-ajax-to="/admin/product/change-value?p=isFeatured&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="No">Yes</a>'
                                : '<a href="##" class="'. $class .' label-warning" data-ajax-to="/admin/product/change-value?p=isFeatured&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="Yes">No</a>';
                            };
        $isFeaturedColumn->setContent(new OeZend_Widget_Grid_Column_Content_CallBack($callBackFunction));
        $isFeaturedColumn->addAttribute(array('class' => 'center'));

        $isBestSellingColumn = new OeZend_Widget_Grid_Column('is_best_selling_label');
        $isBestSellingColumn->setFilter('Combobox');
        $isBestSellingColumn->setLabel('Best Selling');
        $callBackFunction = function ($rs) {
                                $class = 'ajax-link-must-confirm popup hint  label';
                                return ($rs['is_best_selling'] == Model_DbTable_Product::STATUS_ACTIVE)
                                ? '<a href="##" class="'. $class .' label-success" data-ajax-to="/admin/product/change-value?p=isBestSelling&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="No">Yes</a>'
                                : '<a href="##" class="'. $class .' label-warning" data-ajax-to="/admin/product/change-value?p=isBestSelling&id=' . $rs['id'] . '" data-must-confirm-msg="Do you want change this ?" title="Thay đổi" data-after-ajax="Yes">No</a>';
                            };
        $isBestSellingColumn->setContent(new OeZend_Widget_Grid_Column_Content_CallBack($callBackFunction));
        $isBestSellingColumn->addAttribute(array('class' => 'center'));

        $thumbnailColumn = new OeZend_Widget_Grid_Column();
        $thumbnailColumn->setLabel('Thumbnail');
        $thumbnaillink = '<img src="${thumbnail_link}" class="img-thumbnail-grid"/>';
        $thumbnailColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($thumbnaillink));
        $thumbnailColumn->addAttribute(array('class' => 'center'));

        $imgMgmtColumn = new OeZend_Widget_Grid_Column();
        $imgMgmtColumn->setLabel('Images');
        $imgMgmtlink = '<a href="/admin/product-image/index/id/${id}"><i class="icon-picture"></i></a>';
        $imgMgmtColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($imgMgmtlink));
        $imgMgmtColumn->addAttribute(array('class' => 'center', 'width' => '4%'));

        $linkColumn = new OeZend_Widget_Grid_Column();
        $linkColumn->setLabel('Edit');
        $link = '<a href="/admin/product/update/id/${id}"><i class="icon-edit"></i></a>';
        $linkColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($link));
        $linkColumn->addAttribute(array('class' => 'center', 'width' => '4%'));

        $linkDeleteColumn = new OeZend_Widget_Grid_Column();
        $linkDeleteColumn->setLabel('Delete');
        $linkDelete = '<a href="/admin/product/delete/id/${id}" class="must-confirm"><i class="icon-remove"></i></a>';
        $linkDeleteColumn->setContent(new OeZend_Widget_Grid_Column_Content_Template($linkDelete));
        $linkDeleteColumn->addAttribute(array('class' => 'center', 'width' => '4%'));

        $collectionColumn->addColumns(
                  array(
                        $nameColumn,
                        $codeColumn,
                        $parentCategoryColumn,
                        $categoryColumn,
                        $priceSaleColumn,
                        $priceSaleOffColumn,
                        $productStatusColumn,
                        $statusColumn,
                        $isNewColumn,
                        $isFeaturedColumn,
                        $isBestSellingColumn,
                        $isSaleOffColumn,
                        $thumbnailColumn,
                        $imgMgmtColumn,
                        $linkColumn,
                        $linkDeleteColumn,
                       ));

        $this->setCollectionColumn($collectionColumn);
    }
}


